<%@ page import="com.example.softwareconfigurationcoursedesign.ShopPage.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>搜索结果</title>
</head>
<link href="CSS/SearchResults.css" rel="stylesheet">
<body>
<h1>搜索结果</h1>
<form action="searchProduct" method="get">
    <div>
        <label>关键字:</label>
        <input type="text" id="searchKeyword" name="searchKeyword">
        <button type="submit">搜索</button>
    </div>
</form>
<table id="searchResultsTable">
    <%
        Connection connection;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String jdbcUrl = "jdbc:mysql://localhost:3306/course_design";
            String username = "root";
            String password = "123456";
            connection = DriverManager.getConnection(jdbcUrl, username, password);
            connection.createStatement();
        } catch (Exception ignored) {
        } finally {
        }
    %>
    <tr>
        <th>ID</th>
        <th>产品ID</th>
        <th>产品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>URL</th>
        <th>详情</th>
    </tr>
    <%
        List<Product> searchResults = (List<Product>) request.getAttribute("productList");
        if (searchResults != null) {
            for (Product product : searchResults) {
    %>
    <tr>
        <td class="tablesOfId"><%= product.getId()%></td>
        <td><%= product.getPid()  %></td>
        <td><%= product.getPname()  %></td>
        <td class="tablesOfPrice"><%= product.getPprice() %></td>
        <td class="tablesOfTag"><%=product.getPtag() %></td>
        <td><%= product.getDetail()%></td>
        <td><img src="<%= product.getPurl()%>" style="height: 100px;width: 100px"></td>
        <td>
            <button onclick="openEditProductWindow()">编辑</button>
            <form action="DeleteProductServlet" method="post">
                <input type="hidden" name="productId" value="<%= product.getDetail()%>">
                <button>删除</button>
            </form>
        </td>
    </tr>
    <%
            }
        }
    %>
</table>
<script>
    function openEditProductWindow() {
        window.open("editProduct.jsp", "_blank", "width=400,height=300");
    }

</script>
</body>
</html>